import { View } from "../../../mvc/core/View";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Alert } from "../../../../com/mui/controls/Alert";
import { ItemData } from "../../resource/info/ItemData";
import { ShopConfig } from "../../resource/ShopConfig";
import { Cache } from "../../cache/Cache";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
type int = number;
//class FairylandPropItem
    
    export  class FairylandPropItem extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public set isDirect(arg1: Boolean)
        {
            this._isDirect = arg1;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.PackItemBg);
            loc1.x = 1;
            loc1.y = 1;
            addChild(loc1);
            this._item = new BaseItem();
            this._item.setSize(33, 33);
            this._item.move(3, 3);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            addChild(this._item);
            var loc2=ObjCreate.createGButton(Language.getString(60110), 0, 40, 40, 25, this, "Button");
            loc2.addEventListener(flash.events.MouseEvent.CLICK, this.onUseBtnClickHandler);
            return;
        }

        /* internal  */onBuyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            QuickBuyWindow.instance.updateWindow(ECategory._ECategoryProp, EProp._EPropLottery, this._itemData.itemInfo.item.itemLevel);
            QuickBuyWindow.instance.updateDefaultAmount(1);
            QuickBuyWindow.instance.show();
            return;
        }

        /* internal  */onUseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=this.getLotteryItemData(this._itemData.itemInfo.item.itemLevel);
            if (loc1 != null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TreasureUseProp, loc1));
            }
            else if (this._isDirect) 
            {
                if (this._shopItemInfo) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.TreasureBuyAndUseProp, {"shopCode": this._shopItemInfo.tshopSell.shopCode, "itemCode": this._itemData.itemCode}));
                }
            }
            else 
            {
                loc2 = this._itemData.itemInfo.item;
                loc3 = ColorConfig.instance.getItemColor(loc2.color).color;
                loc4 = HTMLUtil.addColor(loc2.name, loc3);
                loc5 = "<font color=\'#ffffff\'>" + loc4 + Language.getString(60111) + "</font>";
                Alert.show(loc5, null, Alert.OK | Alert.CANCEL, null, this.onClickHandler);
            }
            return;
        }

        /* internal  */onClickHandler(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                this.onBuyBtnClickHandler();
            }
            return;
        }

        public /* override */ update(arg1: Object, ... rest): void
        {
            this._itemData = arg1 as ItemData;
            this._item.itemData = this._itemData;
            this._item.drawNow();
            this._shopItemInfo = ShopConfig.instance.getItemByType(ECategory._ECategoryProp, EProp._EPropLottery, this._itemData.itemInfo.item.itemLevel);
            this.updatePropNum();
            return;
        }

        /* internal  */getLotteryItemData(arg1: int): ItemData
        {
            var loc1=Cache.instance.pack.backPackCache.getItemByCode(this._itemData.itemCode);
            return loc1;
        }

        public updatePropNum(): void
        {
            this._item.itemData = this._itemData;
            var loc1=this.getLotteryItemData(this._itemData.itemInfo.item.itemLevel);
            if (loc1 == null) 
            {
                this._item.setAmountText(0);
            }
            else 
            {
                this._item.setAmountText(loc1.itemAmount);
            }
            return;
        }

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_isDirect: Boolean=false;

        /* internal */ /* var */_shopItemInfo: ShopItemInfo;
    }
